﻿// Copyright (c) 2014 Jonathan Magnan (http://jonathanmagnan.com).
// All rights reserved (http://jonathanmagnan.com/icon-library).
// Licensed under MIT License (MIT) (http://ziconlibrary.codeplex.com/license).

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Z.GenerateIconProject.WinForm.BL;
using Z.GenerateIconProject.WinForm.Properties;

namespace Z.GenerateIconProject.WinForm
{
    public partial class MainForm2 : Form
    {
        /// <summary>Default constructor.</summary>
        public MainForm2()
        {
            InitializeComponent();

            //// Initialize
            //if (Settings.Default.WorkingDirectoryPath == "")
            //{
            //    Settings.Default.WorkingDirectoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "zIconWorkingDirectory");
            //    Settings.Default.Save();
            //}

            //RebindForm();
        }

        /// <summary>
        ///     Rebind form.
        /// </summary>
        public void RebindForm()
        {
            //StartPosition = FormStartPosition.CenterScreen;

            //uiNotification.Text = "";

            //uiWorkingDirectoryPath.Text = Settings.Default.WorkingDirectoryPath;
            //uiNamespace.Text = Settings.Default.GenerateNamespace;
            //uiIcon16Path.Text = Settings.Default.GenerateIcon16Path;
            //uiIcon32Path.Text = Settings.Default.GenerateIcon32Path;
        }

        /// <summary>Event handler. Called by uiReset for click events.</summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">Event information.</param>
        private void uiReset_Click(object sender, EventArgs e)
        {
            //uiWorkingDirectoryPath.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "zIconWorkingDirectory");
            //uiNamespace.Text = "Z.IconLibrary";
            //uiIcon16Path.Text = "";
            //uiIcon32Path.Text = "";
        }

        /// <summary>
        ///     Saves the setting value.
        /// </summary>
        public void SaveSettingValue()
        {
            //Settings.Default.WorkingDirectoryPath = uiWorkingDirectoryPath.Text;
            //Settings.Default.GenerateNamespace = uiNamespace.Text;
            //Settings.Default.GenerateIcon16Path = uiIcon16Path.Text;
            //Settings.Default.GenerateIcon32Path = uiIcon32Path.Text;

            //Settings.Default.Save();
        }

        /// <summary>
        ///     Shows the notification success.
        /// </summary>
        /// <param name="message">The message.</param>
        public void ShowNotificationSuccess(string message)
        {
            //uiNotification.Text = message;
            //uiNotification.ForeColor = Color.Green;
        }

        /// <summary>
        ///     Shows the notification error.
        /// </summary>
        /// <param name="message">The message.</param>
        public void ShowNotificationError(string message)
        {
            //uiNotification.Text = message;
            //uiNotification.ForeColor = Color.Red;
        }

        /// <summary>
        ///     Gets the is valid working directory.
        /// </summary>
        /// <returns>A Result.</returns>
        private Result IsValidWorkingDirectory()
        {
            //var workingDirectory = new WorkingDirectory {DirectoryPath = uiWorkingDirectoryPath.Text};
            //Result result = workingDirectory.ValidateAndCreate();

            //if (result)
            //{
            //    uiWorkingDirectoryPath.Text = workingDirectory.DirectoryPath;
            //}
            //else
            //{
            //    ShowNotificationError(result.Message);
            //}

            //return result;
            return null;
        }

        /// <summary>Event handler. Called by uiGenerate for click events.</summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">Event information.</param>
        private void uiGenerate_Click(object sender, EventArgs e)
        {
            //if (!IsValidWorkingDirectory())
            //{
            //    return;
            //}

            //var generate = new GenerateProject
            //{
            //    WorkingDirectory = new WorkingDirectory {DirectoryPath = uiWorkingDirectoryPath.Text},
            //    Namespace = uiNamespace.Text,
            //    Icon16DirectoryPath = uiIcon16Path.Text,
            //    Icon32DirectoryPath = uiIcon32Path.Text,
            //    IsLegacy = uiIsLegacy.Checked
            //};

            //Result result = generate.IsValid();
            //if (result)
            //{
            //    try
            //    {
            //        bool isFileSynchronized = generate.EnsureFileSynchronized();
            //        if (!isFileSynchronized)
            //        {
            //            ShowNotificationError(My.Message.Error.EM208);
            //            return;
            //        }

            //        MessageBox.Show(My.Message.Warning.WM201, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //        generate.Generate();
            //        ShowNotificationSuccess(My.Message.Success.SM201);
            //        SaveSettingValue();
            //    }
            //    catch (Exception ex)
            //    {
            //        ShowNotificationError(My.Message.Error.EM101 + ":" + ex.Message + Environment.NewLine + "Try again");
            //    }
            //}
            //else
            //{
            //    ShowNotificationError(result.Message);
            //}
        }
    }
}